var app = getApp();
var WxParse = require("../../../../wxParse/wxParse.js");
let isclick = true;
var optionsMaxCount = 1;
Component({
  properties: {
    prop_goods_info: {
      type: null, //父组件的商品详情数据
    },
    producerId: {
      // 厂家商品
      type: Number,
    },
    // 属性值可以在组件使用时指定
    goodsId: {
      type: Number,
    },
    goodsType: {
      type: String,
    },
    mark: {
      type: String,
    },
    hoet: {
      type: null,
    },
    datop: {
      type:null,
    },
    markId: {
      type: null,
    },
    showIn: {
      type: null,
    },
    vieText: {
      type: null,
    },
    boxHeight: {
      type: Number,
    },
    xqBoxShow: {
      type: null,
    },
    ipnonexbol: {
      type: null,
    },
    activityid: {
      type: null,
    },
    share_uid: {
      type: null,
    },
    fromStock: {
      // 云库存商品
      type: String || Number,
    },
    enterAt: {
      type: Object,
    },
    // 拼团store_id
    store_id: {
      type: null,
    },
    // 拼团
    fight_groups: {
      type: null,
    },
    mode: {
      // 新零售 mode==2为代理套餐，购买数量不可修改  底部导航显示
      type: null,
    },
    coid:{
      // 默认规格id
      type:null
    },
    debtId:{
      // 置换亿栈债务人店铺id
      type:null
    },
    cid:{
      type:null
    },
    // 详情页面接受的传参
    options:{
      type:null,
      value:{}
    }
  },
  data: {
    goods_plugin: {}, //插件plugin的数据
    goods_info: {}, //data全部的数据或者get_goods的数据
    goodsInfo: "", //get_goods的数据或者goods_info的数据
    gooddatas: "", // data全部的数据
    // 应用市场开关
    is_market: false,
    marketShow: "",

    language: "",
    // xqBoxShow: false,
    // 图片域名
    imagUrl: app.globalData.imgPath,
    // 这是参数弹窗
    showCs: false,
    // 这是tab
    current: 1,
    //动态模糊框
    popupModeshow: true,
    //限时购开关
    isBuy: false,
    isTime: false,
    //限时购开始时间
    beginTime: 0,
    //显示购结束时间
    endTime: 0,
    //定制团开始时间
    grBeginTime:0,
    grisTime:false,
    grBegTimeStr:'',
    //计算后的倒计时
    countDownObj: {
      day: "00",
      hou: "00",
      min: "00",
      sec: "00",
    },
    //是否显示爱心值
    isGoodsLove: false,
    //爱心值 现金
    goods_love_cash: 0,
    //爱心值抵扣
    goods_love_deduction: 0,
    //爱心值title
    goods_love_name: "",
    //是否租赁商品
    isRent: false,
    isRight: false,
    //立即购买
    isRentBuyShow: false,
    isGoods: false,
    SUBMIT_ACTION_CART: "-1", //添加到购物车
    SUBMIT_ACTION_BUY: "-2", //立即购买
    submitActionTag: "",
    optionsId: "", //选择后的 规格ID
    popupSpecs: false,
    goodsCount: 1,
    optionsMaxCount: 1,
    popupSpecs2: false, //无规格选择商品数量
    popThumb: "",
    popStock: 0,
    popPrice: 0,
    specsManage: [], //选择池 用于排序
    goodsDescription: "",
    //是否门店拼团
    is_o2o: false,
    favorite: false,
    isAddCart: false,
    activeName: 0,
    //商品详情
    currentTabIndex: "0",
    first_content: "",
    second_content: "",
    third_content: [],
    //标记防止重复加载
    is_first_content: false,
    is_second_content: false,
    is_third_content: false,
    // 初始评论页数
    commentPage: 1,
    // 是否有更多评论
    noMoreComment: false,
    //海报显隐
    posterShow: false,
    posterImg: "",
    //限时购据开始时间开关
    isBegTime: false,
    begTimeStr: "",
    //限时购据开始时间倒计时
    beginDownObj: {
      day: "00",
      hou: "00",
      min: "00",
      sec: "00",
    },
    replyBol: false,
    get_guidepage_info: {},
    //more
    isLoadMore: true,
    page: 1,
    total_page: 0,
    roomdataBol: false,
    roomdata: [],
    min_micro: [],
    tabList: [], //微贴和直播
    customer_open: true,
    show1: false,
    iPnoneBottomBol: false,

    skuImages: [],
    showSkuImages: false,
    activeSkuIndex: 0,
    activeSkuIndex_1: null, //用于关闭时保存点击预览前的序号，在预览关闭时重新设置预览起始位置
    activeSkuIndex_2: null,

    luck_draw: {}, //新抽奖抽奖luck-draw悬浮按钮
    btnData: {
      over_top: 500,
      icon_url: app.globalData.imgPath + "icon-fontclass-zhiding.png"
    },
    // 海报按钮
    btnData2: {
      over_top: 450,
      icon_url: app.globalData.imgPath + "bc_eweima.png"
    },
    showMoreParams: false, //商品参数展示

    //打开分享弹窗
    showSahre: false,
    // 是否开启好物圈插件
    wechatcircle_open: 0,
    //运费说明
    freight_pricing: {},
    freightPricing_main_heigth: null,
    freightPricing_main_heigth_var: null,
    isfold: false, //运费说明展开收起状态
    nocart: false, //是否显示购物车

    broadcast_data: [], //飘窗订单数据
    selfbuy_discount: null, //自购省数据
    wx_video_link: 0, //视频号扩展插件
    showVideoLink: false,
    article_url: null, // 视频号扩展链接

    integral: "积分",
    //活动是否结束
    isTimeEnd: false,
    ispt: false,
    cart_num: '', //购物车数量
    MachineId:'',//自动售货机id
    // 会员中心按钮是否显示
    is_member_enter:true,
    //律师信息
    lawyerInfo:{
      name:'',
      price:'',
      status:'',
      service_day:'',
      service_type:'',
      l_id:'',
      l_name:'',
      lf_id:'',
      lf_name:'',
      lf_province_name:'',
      lf_city_name:'',
      lf_area_name:'',
      lf_street_name:'',
      lf_address_detail:'',
    },

    
  },
  observers:{
    'prop_goods_info':function(info){
      this.setData({
        is_member_enter:info.get_goods && info.get_goods.is_member_enter == 1?true:false
      });
    },
    'datop':function(top){
      if(top >= this.data.xqtop){
        this.setData({
          current:3
        })
      }else if(top >= this.data.pjtop){
        this.setData({
          current:2
        })
      }else{
        this.setData({
          current:1
        })
      }
    }
  },
  lifetimes: {
    attached(e) {
      // 海报设置 start
      let selfPoster = ['grabGroup','group_goods','zhpGroup','groupwork','ywmGroup'];
      this.setData({
        ispt: selfPoster.includes(this.data.goodsType) ? this.data.goodsType: false
      });
      if(this.properties.activityid){
        this.setData({
          activity_id: this.properties.activityid,
          activityId: this.properties.activityid
        });
      }
      if(this.properties.share_uid){
        this.setData({
          share_uid: this.properties.share_uid
        });
      }
      if (this.data.goodsType == "zhpGroup") {
        this.setData({
          activityId: this.properties.goodsId
        });
      }
      // 海报设置 end

      isclick = true;
      this.getiPnoneBottom();
      let language = wx.getStorageSync("langIndex");
      this.setData({
        language: language.en,
        cart_num: app.globalData.cart_num
      });
      // 客服初始化
      this.init();
      if (this.data.producerId) {
        this.getManage();
      }
      if (!this.data.producerId) {
        // key: this.goods_type
        // value: 对应调用的Methob
        let pluginMethob = new Map([
          ["group_goods", "groupGetData"],
          ["ywmGroup", "groupGetData"],
          ["grabGroup", "grabGroupData"],
          ["retailGood", "retailPage"],
          ["zhpGroup", "zhpGroupData"],
          ["groupwork", "groupWorkData"]
        ]);
        let handleType = pluginMethob.has(this.data.goodsType)?pluginMethob.get(this.data.goodsType): 'getGoodsPage';

        if (this.data.goodsType == "group_goods"||this.data.goodsType == "ywmGroup") {
          this.setData({
            activityid: this.properties.goodsId,
            goodsInfo: {},
          });
          this.data.specsManage = [];
          this.getCommentData();
        }
        this[handleType]();//调用对应的方法
      }

      if(this.data.mark == 'vending_machine'){
        this.setData({MachineId:this.data.markId})
      }
      // 赋值给foot组件
      let footChild = this.selectComponent("#footChild");
      if (this.data.fromStock == 1 || this.data.fromStock == 2) {
        footChild.setData({
          nocart: true,
        });
      }

      wx.createSelectorQuery()
        .in(this)
        .select(".goodsdetail")
        .boundingClientRect()
        .exec((rect = []) => {
          // 解决个别屏幕比较长时，goodsdetail元素的高度不够上拉【项目编号：#61673】
          if (rect[0].height < wx.getSystemInfoSync().windowHeight) {
            this.setData({
              xqBoxShow: true,
            });
          }
        });
    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
    ready() {
      let that = this;
      try {
        this.createSelectorQuery()
        .select(".sift")
        .boundingClientRect(function (rect) {
          if(rect) that.setData({ pjtop: rect.top - 80 });
        })
        .exec();
      this.createSelectorQuery()
        .select(".foShowBox")
        .boundingClientRect(function (rect) {
          that.setData({
            xqtop: rect.top - 100,
          });
        })
        .exec();
      } catch (error) {
        console.log(error)
      }

      const value = wx.getStorageSync("integral");
      if (value) {
        this.setData({
          integral: value,
        });
      }
    },
  },
  methods: {
    contorBuyNow(){
      if(this.data.goodsType == 'goods' || this.data.goodsType == 'supplierGoods'){
        let foot = this.selectComponent('#footChild');
        foot.buyNow('design');
      }
    },
    getOptionsId(e){
      if(this.data.goodsType == 'goods' || this.data.goodsType == 'supplierGoods'){
        let arr = this.data.gooddatas.get_goods.has_many_options;
        let self = this.selectComponent('#Tag');
        let title ='';
        for(let i = 0;i<arr.length;i++){
          if(e.detail.option == arr[i].id){
            title = arr[i].title;
          }
        }
        self.setData({
          'optionObj.title':title,
          'optionObj.total':e.detail.goodsCount
        });
        if(this.data.goods_plugin && this.data.goods_plugin.goods_stock_judgment){
          let adop = this.selectComponent('#adop');
          adop.setData({
            judgmentOptionId:e.detail.option
          })
          adop.getData();
        }
      }
    },
     // addressOption 组件返回当前地址是否有货 state == 1有货，==2无货
     childAdressStateMethod(e){
      // 是否禁用加入购物车和立即下单 goodsAction组件方法
      console.log(e,'childAdressStateMethod')
      let state = e.detail;
      let foot = this.selectComponent("#footChild");
      foot.childAdressPost(state)
    },
    gotoLuckDraw(){
      wx.navigateTo({
        url: '/packageH/newDraw/luckyDraw/luckyDraw'
      });
    },
    changeCartNumber() {
      this.setData({
        cart_num: app.globalData.cart_num
      });
    },
    // 分享弹窗
    openShare() {
      this.setData({
        showSahre: true,
      });
    },
    // 分享弹窗关闭
    closeSharePop() {
      this.setData({
        showSahre: false,
      });
    },
    //收藏操作
    onFavorite(e) {
      this.data.favorite ? this.removeFavorite() : this.addFavorite();
    },
    //移除收藏
    removeFavorite() {
      let urlStr = app.getNetAddresss("member.member-favorite.destroy");
      urlStr += "&goods_id=" + this.data.goodsId;
      app._getNetWork({
        url: urlStr,
        success: (resdata)=> {
          var res = resdata.data;
          if (res.result == 1) {
            this.setData({
              favorite: false,
            });
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },
    //添加收藏
    addFavorite() {
      let urlStr = app.getNetAddresss("member.member-favorite.store");
      urlStr += "&goods_id=" + this.data.goodsId;
      app._getNetWork({
        url: urlStr,
        success: (resdata)=> {
          var res = resdata.data;
          if (res.result == 1) {
            this.setData({
              favorite: true,
            });
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    },
    // 分享到好物圈
    shareGoods() {
      let that = this;
      let urlStr = app.getNetAddresss("plugin.wechatcircle_products.api.import.import");
      let data = {
        product_list: [{
          item_code: that.data.goodsInfo.id,
          title: that.data.goodsInfo.title,
          desc: that.data.goodsInfo.title,
          category_list: ["商品"],
          image_list: that.data.goodsInfo.thumb_url,
          src_wxapp_path: "packageA/detail_v2/detail_v2?id=" + that.data.goodsInfo.id,
          sku_list: [{
            sku_id: that.data.goodsInfo.id,
            price: that.data.goodsInfo.price,
            original_price: that.data.goodsInfo.market_price,
            status: 1,
          },],
        },],
      };
      if (isclick) {
        isclick = false;
        app._postNetWork({
          url: urlStr,
          data: data,
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              setTimeout(function () {
                isclick = true;
              }, 1000);
              if (wx.openBusinessView) {
                wx.openBusinessView({
                  businessType: "friendGoodsRecommend",
                  extraData: {
                    product: {
                      item_code: that.data.goodsInfo.id,
                      title: that.data.goodsInfo.title,
                      image_list: that.data.goodsInfo.thumb_url,
                    },
                  },
                  success: function (res) {
                    that.setData({
                      showSahre: false,
                    });
                  },
                  fail: function (res) {
                    console.log("fail", res);
                    that.setData({
                      showSahre: false,
                    });
                  },
                });
              } else {
                wx.showToast({
                  title: "微信7.0.3及以上版本支持 请先更新微信版本",
                  icon: "none",
                  duration: 3000,
                });
              }
            } else {
              wx.showToast({
                title: res.msg,
                icon: "none",
                duration: 3000,
              });
            }
          },
          fail: function (res) {
            setTimeout(function () {
              isclick = true;
            }, 1000);
            console.log(res);
          },
        });
      }
    },
    // 获取手机型号
    getiPnoneBottom() {
      let value = wx.getStorageSync("iPhoneBottom");
      if (value) {
        this.setData({
          iPnoneBottomBol: true,
        });
      }
    },
    // 客服
    init() {
      this.setData({
        wechatcircle_open: 0,
        customer_open: true,
        show1: false,
        service_QRcode: "",
        service_mobile: "",
      });
    },
    // 客服
    callPhone() {
      wx.makePhoneCall({
        phoneNumber: this.data.service_mobile,
      });
    },
    // 客服关闭
    closePop() {
      this.setData({
        show1: false,
      });
    },
    // ---------  引导加群
    handleContact(e) {
      console.log(e.detail);
    },

    replyBolClose() {
      this.setData({
        replyBol: false,
        kefu: false,
      });
    },
    // ---------------- 引导加群end
    toGroupCode() {
      if(this.data.goods_plugin.group_code.jump_mode === 'home') {
        wx.reLaunch({
          url: '/packageE/groupCode/groupCode',
        });
      }else if(this.data.goods_plugin.group_code.code_mini_url){
        wx.navigateTo({
          url: this.data.goods_plugin.group_code.code_mini_url
        });
      }
    },
    // 商品参数
    handlerShowParams () {
      this.setData({
        showMoreParams: !this.data.showMoreParams
      });
    },
    // 服务标签弹窗开启
    showCan(e) {
      this.setData({
        popupModeshow: e.detail
      });
    },
    // 点击顶部导航
    getTap(e) {
      let pid = e.currentTarget.id;
      this.setData({
        current: pid,
      });
      if (pid == 1) {
        wx.pageScrollTo({
          scrollTop: 0,
          duration: 300,
        });
      } else if (pid == 2) {
        wx.pageScrollTo({
          scrollTop: this.data.pjtop,
          duration: 300,
        });
      } else if (pid == 3) {
        this.setData({
          xqBoxShow: true,
        });
        wx.pageScrollTo({
          scrollTop: this.data.xqtop + 150,
          duration: 300,
        });
      } else if (pid == 4) {
        this.setData({
          xqBoxShow: true,
        });
        this.createSelectorQuery()
          .select(".goodsdetail")
          .boundingClientRect(function (rect) {
            wx.pageScrollTo({
              scrollTop: rect.height,
              duration: 300,
            });
          })
          .exec();
      }
    },
    //获取时间-限时购
    _timeCompare(begin) {
      let beginTime = new Date(parseInt(begin) * 1000);
      let now = new Date();
      console.log(beginTime >= now);
      if (now >= beginTime) {
        this.setData({
          isTime: true,
        });
        //开启倒计时
        this._countDown();
      } else {
        this.setData({
          isTime: false,
          isBegTime: true,
          isTimeEnd: false,
          begTimeStr: begin * 1000,
        });
        //开启距离开始倒计时
        this.beginDown();
      }
    },
    //定制团限时购
    groupTime(begin) {
      let beginTime = parseInt(begin) * 1000;
      let now = Date.parse(new Date());
      if (now >= beginTime) {
        return false;
      } else {
        // this.grBegTimeStr = String(beginTime - now);
        this.setData({
          grBegTimeStr:beginTime
        })
        console.log(this.data.grBegTimeStr);
        this.beginDown();
        return  true;
      }
    },
    //倒计时
    _countDown: function () {
      let newTime = new Date().getTime();
      let endTime = this.data.endTime;
      let obj = null;
      if (endTime - newTime > 0) {
        let time = (endTime - newTime) / 1000;
        // 获取天、时、分、秒
        let day = parseInt(time / (60 * 60 * 24));
        let hou = parseInt((time % (60 * 60 * 24)) / 3600);
        let min = parseInt(((time % (60 * 60 * 24)) % 3600) / 60);
        let sec = parseInt(((time % (60 * 60 * 24)) % 3600) % 60);
        obj = {
          day: this._timeFormat(day),
          hou: this._timeFormat(hou),
          min: this._timeFormat(min),
          sec: this._timeFormat(sec),
        };
      } else {
        //活动已结束，全部设置为'00'
        obj = {
          day: "00",
          hou: "00",
          min: "00",
          sec: "00",
        };
      }
      this.setData({
        countDownObj: obj,
      });
      if (endTime - newTime < 0) {
        this.setData({
          countDownObj: {
            day: "00",
            hou: "00",
            min: "00",
            sec: "00",
          },
          isTimeEnd: true,
        });
      } else {
        setTimeout(this._countDown.bind(this), 1000);
      }
    },
    //倒计时
    //grBegTimeStr定制团的倒计时
    beginDown: function () {
      let newTime = new Date().getTime();
      let endTime = this.data.begTimeStr?this.data.begTimeStr:this.data.grBegTimeStr; 
      let obj = null;
      if (endTime - newTime > 0) {
        let time = (endTime - newTime) / 1000;
        // 获取天、时、分、秒
        let day = parseInt(time / (60 * 60 * 24));
        let hou = parseInt((time % (60 * 60 * 24)) / 3600);
        let min = parseInt(((time % (60 * 60 * 24)) % 3600) / 60);
        let sec = parseInt(((time % (60 * 60 * 24)) % 3600) % 60);
        obj = {
          day: this._timeFormat(day),
          hou: this._timeFormat(hou),
          min: this._timeFormat(min),
          sec: this._timeFormat(sec),
        };
      } else {
        //活动已结束，全部设置为'00'
        this.setData({
          isTime: true,
          isBegTime: false,
          isTimeEnd: true,
        });
        obj = {
          day: "00",
          hou: "00",
          min: "00",
          sec: "00",
        };
      }
      this.setData({
        beginDownObj: obj,
      });
      if (endTime - newTime < 0) {
        this.setData({
          isTime: true,
          isBegTime: false,
          isTimeEnd: true,
        });
        this.setData({
          beginDownObj: {
            day: "00",
            hou: "00",
            min: "00",
            sec: "00",
          },
        });
      } else {
        setTimeout(this.beginDown.bind(this), 1000);
      }
    },
    //小于10的格式化函数
    _timeFormat(param) {
      //小于10的格式化函数
      return param < 10 ? "0" + param : param;
    },
    //品牌跳转
    toBrandDetail(e) {
      var brandval = e.currentTarget.dataset.brandval;
      wx.navigateTo({
        url: "/packageB/member/goods/GoodsBrand/GoodsBrand?id=" + brandval,
      });
    },
    // foot子组件接受方法
    addCart(e) {
      let buyNowChild = this.selectComponent("#buyNowChild");
      buyNowChild.setData({
        popupSpecs: e.detail.popupSpecs,
        popupSpecs2: e.detail.popupSpecs2,
        submitActionTag: e.detail.submitActionTag,
      });
      if (e.detail.popupModeshow || !e.detail.popupModeshow) {
        this.setData({
          popupModeshow: e.detail.popupModeshow,
        });
      }
      if (e.detail.popupSpecs || !e.detail.popupSpecs) {
        this.setData({
          popupSpecs: e.detail.popupSpecs,
        });
      }
    },
    // 立即购买
    buyNow() {
      let foot = this.selectComponent("#footChild");
      foot.buyNow();
    },
    // 新零售
    buyNowRetail(e) {
      let buyNowChild = this.selectComponent("#buyNowChild");
      buyNowChild.setData({
        popupSpecs: e.detail.popupSpecs,
        popupSpecs2: e.detail.popupSpecs2,
        submitActionTag: e.detail.submitActionTag,
        isAward: e.detail.isAward ? e.detail.isAward : "",
        buyType: e.detail.buyType,
      });
      if (e.detail.popupModeshow || !e.detail.popupModeshow) {
        this.setData({
          popupModeshow: e.detail.popupModeshow,
        });
      }
    },
    buyNowFoot(e) {
      console.log(this.data.gooddatas);
      if (this.data.gooddatas.join_status === false && (this.data.goodsType === "group_goods"||this.data.goodsType === "ywmGroup")) {
        wx.showToast({
          title: '今日该活动已达到参与次数',
          icon: "none",
          duration: 3000
        });
        return;
      }
      let buyNowChild = this.selectComponent("#buyNowChild");
      buyNowChild.setData({
        popupSpecs: e.detail.popupSpecs,
        popupSpecs2: e.detail.popupSpecs2,
        submitActionTag: e.detail.submitActionTag,
        isAward: e.detail.isAward ? e.detail.isAward : "",
        submitTag:e.detail.submitTag
      });
      if (e.detail.popupModeshow || !e.detail.popupModeshow) {
        this.setData({
          popupModeshow: e.detail.popupModeshow,
        });
      }
    },
    //初始化弹窗view
    initPopView() {
      let buyNowChild = this.selectComponent("#buyNowChild");
      if (this.data.goodsType == "group_goods" || this.data.goodsType == 'zhpGroup' ||this.data.goodsType == 'ywmGroup') {
        // 拼团的初始化
        buyNowChild.setData({
          // 设置默认价格
          popPrice: this.data.gooddatas.min_price + "起",
        });
        if (this.data.goodsInfo.has_option == 1) {
          this.setData({
            popStock: this.data.gooddatas.stock,
            // 设置默认库存
            goodsDescription: "选择",
          });

          let _optionArr = [];
          this.data.goodsInfo.has_many_options.forEach((val, index) => {
            let _thumb = val.thumb ? val.thumb : this.data.goodsInfo.thumb;
            _optionArr.push(_thumb);
          });
          // 传给buyNow子组件的
          buyNowChild.setData({
            popStock: this.data.popStock,
            goodsDescription: "选择",
            skuImages: _optionArr,
          });
        } else {
          let __optionArr2 = [];
          __optionArr2.push(this.data.goodsInfo.thumb);
          if (this.data.goodsType == 'group_goods'||this.data.goodsType == 'ywmGroup') {
            optionsMaxCount = this.data.gooddatas.has_many_options[0].buy_limit == 0 ? this.data.gooddatas.has_many_options[0].stock : this.data.gooddatas.has_many_options[0].buy_limit; // 当前购买限制数, 为0 时为无限制购买
          } else {
            optionsMaxCount = this.data.gooddatas.has_many_options[0].stock;
          }
          this.setData({
            popStock: this.data.gooddatas.stock, // 当前库存
            groupStock: this.data.gooddatas.has_many_options[0].stock, // 当前库存
            skuImages: __optionArr2,
            optionsMaxCount: optionsMaxCount
          });
          // 传给buyNow子组件的
          buyNowChild.setData({
            popStock: this.data.popStock,
            groupStock: this.data.gooddatas.has_many_options[0].stock,
            skuImages: __optionArr2,
          });
        }
      } else if (this.data.goodsType == "grabGroup") {
        // 抢团的初始化
        try {
          this.setData({
            "gooddatas.has_option": this.data.gooddatas.has_many_specs.length > 0 ? 1 : 0,
          });
        } catch (error) {
          this.setData({
            "gooddatas.has_option": 0,
          });
        }

        let _optionArr = [];
        this.data.gooddatas.has_many_options.forEach((val, index) => {
          let _thumb = val.thumb != null ? val.thumb : this.data.gooddatas.thumb;
          _optionArr.push(_thumb);
        });
        this.setData({
          _optionArr: _optionArr,
        });

        if (this.data.gooddatas.has_option == 1) {
          this.setData({
            popPrice: this.data.gooddatas.min_price + "-" + this.data.gooddatas.max_price, //设置默认价格
            popThumb: this.data.gooddatas.thumb, //设置默认图片
            popStock: this.data.gooddatas.stock, //设置默认库存
            goodsDescription: "选择",
          });
          for (let i = 0; i < this.data.gooddatas.has_many_specs.length; i++) {
            this.setData({
              goodsDescription: this.data.goodsDescription + " " + this.data.gooddatas.has_many_specs[i].title,
            });
          }
        } else {
          this.setData({
            popThumb: this.data.gooddatas.thumb, //设置默认图片
            popStock: this.data.gooddatas.stock, //设置默认库存
            popPrice: this.data.gooddatas.price, //设置默认价格
            goodsDescription: "",
            optionsMaxCount: this.data.gooddatas.stock,
          });
        }
      } else {
        let popPrice = "";
        if (this.data.goodsInfo.has_option == 1) {
          if (this.data.goods_plugin.point_goods) {
            popPrice = this.data.goods_plugin.point_goods.min_point + "-" + this.data.goods_plugin.point_goods.max_point; //设置默认价格
          } else {
            popPrice = this.data.goodsInfo.min_price + "-" + this.data.goodsInfo.max_price; //设置默认价格
          }
          for (let i = 0; i < this.data.goodsInfo.has_many_specs.length; i++) {
            this.setData({
              goodsDescription: this.data.goodsDescription + " " + this.data.goodsInfo.has_many_specs[i].title,
            });
          }
          let _optionArr = [];
          this.data.goodsInfo.has_many_options.forEach((val, index) => {
            let _thumb = val.thumb != "" ? val.thumb : this.data.goodsInfo.thumb;
            _optionArr.push(_thumb);
          });
          // 传给buyNow子组件的
          buyNowChild.setData({
            popStock: this.data.goodsInfo.stock,
            popThumb: this.data.goodsInfo.thumb,
            popPrice: popPrice,
            goodsDescription: "选择",
            optionsMaxCount: this.data.goodsInfo.stock,
            skuImages: _optionArr,
          });
        } else {
          let __optionArr2 = [];
          __optionArr2.push(this.data.goodsInfo.thumb);

          if (this.data.goods_plugin.point_goods) {
            popPrice = this.data.goods_plugin.point_goods.point; //设置默认价格
          } else {
            popPrice = this.data.goodsInfo.price; //设置默认价格
          }
          // 传给buyNow子组件的
          buyNowChild.setData({
            popStock: this.data.goodsInfo.stock,
            popThumb: this.data.goodsInfo.thumb,
            popPrice: popPrice,
            goodsDescription: "",
            optionsMaxCount: this.data.goodsInfo.stock,
            skuImages: __optionArr2,
            goodsCount:this.data.goodsInfo.min_buy_num,
          });
        }
      }
    },
    // 关闭购买弹窗
    showSkuImages_Methob_child(e) {
      this.setData({
        popupModeshow: e.detail,
      });
    },
    //租赁立即购买
    toRentBuy(e) {
      let immedid = e.currentTarget.dataset.immedid;
      wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=" + immedid,
      });
    },
    //设置选择后的数据
    setDataByTabIndex() {
      if (this.data.currentTabIndex == "0" && !this.data.is_first_content) {
        this.data.is_first_content = true;
        this.setData({
          first_content: this.data.goodsInfo.content,
        });
      } else if (this.data.currentTabIndex == "1" && !this.data.is_second_content) {
        this.setData({
          is_second_content: true,
          second_content: this.data.goodsInfo.has_many_params,
        });
      } else if (this.data.currentTabIndex == "2" && !this.data.is_third_content) {
        this.setData({
          is_third_content: true,
        });
        //获取评论
        this.getCommentData();
      }
    },
    //获取评论数据
    getCommentData() {
      let that = this;
      let urlStr = app.getNetAddresss("goods.comment.get-comment");
      urlStr += "&goods_id=" + this.data.goodsId;
      urlStr += "&page=" + this.data.commentPage;
      app._getNetWork({
        showToastIn: false,
        url: urlStr,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            if (res.data.data.length < 20) {
              that.setData({
                noMoreComment: true,
              });
            }
            that.setData({
              commentPage: that.data.commentPage + 1,
            });
            if (!that.data.third_content) {
              that.setData({
                third_content: [],
              });
            }
            that.setData({
              third_content: [...that.data.third_content, ...res.data.data],
            });

            if (app._isTextEmpty(that.data.third_content)) {
              console.log("空没评论");
              that.setData({
                thirKong: false,
              });
            } else {
              console.log("不空");
              that.setData({
                thirKong: true,
              });
            }
          } else {
            that.setData({
              is_third_content: false,
            });
          }
        },
        fail: function (res) {
          that.setData({
            is_third_content: false,
          });
          console.log(res);
        },
      });
    },
    gotoindex() {
      wx.navigateTo({
        url: '/packageG/index/index'
      });
    },
    //海报生成
    postShow(e) {
      console.log(e);
      this.setData({
        posterShow: true,
        showSahre: false,
      });
    },
    posterClose() {
      this.setData({
        posterShow: false,
      });
    },
    saveImg() {
      wx.getSetting({
        success(res) {
          if (!res.authSetting["scope.writePhotosAlbum"]) {
            wx.authorize({
              scope: "scope.writePhotosAlbum",
              success() {
                console.log("授权成功");
              },
            });
          }
        },
      });
      var imgSrc = this.data.posterImg.image_url;
      wx.downloadFile({
        url: imgSrc,
        success: function (res) {
          console.log(res);
          //图片保存到本地
          wx.saveImageToPhotosAlbum({
            filePath: res.tempFilePath,
            success: function (data) {
              wx.showToast({
                title: "保存成功",
                icon: "none",
                duration: 3000,
              });
            },
            fail: function (err) {
              console.log(err);
              if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
                console.log("当初用户拒绝，再次发起授权");
                wx.openSetting({
                  success(settingdata) {
                    if (settingdata.authSetting["scope.writePhotosAlbum"]) {
                      wx.showToast({
                        icon: "none",
                        title: "获取权限成功,再次长按保存图片",
                        duration: 3000,
                      });
                    } else {
                      wx.showToast({
                        icon: "none",
                        title: "获取权限失败,保存图片需要用户授权",
                        duration: 3000,
                      });
                    }
                  },
                });
              }
            },
            complete(res) {
              console.log(res);
            },
          });
        },
      });
    },
    gotoMember() {
      wx.reLaunch({
        url: "/packageG/member_v2/member_v2",
      });
    },
    //直播间跳转
    gopage(e) {
      let status = e.currentTarget.dataset.status;
      let id = e.currentTarget.dataset.id;
      let backid = e.currentTarget.dataset.backid;
      if (status == 1) {
        wx.navigateTo({
          url: "/packageD/directSeeding/livePage/livePage?id=" + id + "&playerType=live",
        });
      } else if (status == 2) {
        wx.navigateTo({
          url: "/packageD/directSeeding/livePage/livePage?id=" + id + "&playerType=video" + "&backid=" + backid,
        });
      } else if (status == 3) {
        wx.navigateTo({
          url: "/packageD/directSeeding/foreshow/foreshow?id=" + id,
        });
      }
    },
    // 获取直播间列表
    getLiveList() {
      let urlStr = app.getNetAddresss("goods.goods.get-room");
      app._postNetWork({
        url: urlStr,
        showToastIn: false,
        data: {
          page: this.data.page,
          goods_id: this.data.goodsId,
        },
        success: (resdata)=> {
          var res = resdata.data;
          if (res.result == 1) {
            let list = [];
            for(let i=0;i<res.data.data.length;) {
              list.push(res.data.data.slice(i, i + 2));
              i += 2;
            }
            this.setData({
              total_page: res.data.last_page,
              roomdata: list,
              roomdataBol: true,
            });
            if(this.data.roomdata.length > 0) {
              this.setData({
                tabList: this.data.tabList.concat([{id: 2,name: '直播间'}])
              });
            }
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
        fail: (res)=> {
          console.log(res.msg);
        },
      });
    },
    _getMoreData() {
      let that = this;
      let urlStr = app.getNetAddresss("goods.goods.get-room");
      that.data.isLoadMore = false; // 防止多次请求分页数据
      if (this.data.page >= this.data.total_page) {
        return;
      } else {
        this.data.page = this.data.page + 1;
        app._postNetWork({
          url: urlStr,
          showToastIn: false,
          data: {
            page: this.data.page,
            goods_id: this.data.goodsId,
          },
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              that.setData({
                isLoadMore: true,
                roomdata: that.data.roomdata.concat(res.data.data),
              });
            } else {
              that.setData({
                page: that.data.page - 1,
                isLoadMore: false,
              });
            }
          },
          fail: function (res) {
            console.log(res.msg);
          },
        });
      }
    },
    // 获取直播间列表end
    reachBottom() {
      if (this.data.roomdataBol) {
        if (this.data.isLoadMore) {
          this._getMoreData();
        } else {
          console.log("没有更多数据");
        }
      }
    },
    // 厂家商品请求
    getManage() {
      let that = this;
      let footChild = this.selectComponent("#footChild");
      let buyNowChild = this.selectComponent("#buyNowChild");
      let urlStr = app.getNetAddresss("plugin.producer.frontend.goods.getGoodsPage");
      app._postNetWork({
        url: urlStr,
        showToastIn: false,
        data: {
          id: this.data.goodsId,
          producer_id: this.data.producerId,
          mark: this.data.mark,
          mark_id: this.data.markId,
          url: "",
        },
        success: (resdata)=> {
          var res = resdata.data;
          if (res.result == 1) {
            if (res.data.wechatcircle_open && res.data.wechatcircle_open == 1) {
              that.setData({
                wechatcircle_open: 1,
              });
            }
            that.getData(res.data.get_goods);

            that.setData({
              broadcast_data: res.data.broadcast_data,
              favorite: res.data.is_favorite ? (res.data.is_favorite.status == 1 ? true : false) : false,
              customer_open: res.data.customer_open == "1" ? true : false,
              service_QRcode: res.data.service_QRcode,
              service_mobile: res.data.service_mobile,
              freight_pricing: res.data.plugin && res.data.plugin.freight_pricing ? res.data.plugin.freight_pricing : {},
              producer_info: res.data.producer_info,
              goodsType: res.data.goods_type.goods_type,
              goods_info: res.data.get_goods,
              gooddatas: res.data,
            });
            // foot子组件赋值
            footChild.setData({
              goodsInfo: that.data.goods_info,
              service_QRcode: res.data.service_QRcode,
              service_mobile: res.data.service_mobile,
              customer_open: res.data.customer_open,
            });
            // buynow子组件赋值
            buyNowChild.setData({
              gooddatas: that.data.prop_goods_info.plugin || {},
            });
            // console.log(that.data.prop_goods_info);
            if (res.data.plugin && res.data.plugin.wx_video_link) {
              that.setData({
                wx_video_link: res.data.plugin.wx_video_link,
              });
            }

            //运费说明
            let Shipping = that.data.freight_pricing.content;
            try {
              if (Shipping && Shipping.indexOf("&#") <= -1) {
                WxParse.wxParse("Shipping", "html", Shipping, that);
              }
            } catch (e) {
              //TODO handle the exception
            }

            if (res.data.get_guidepage_info) {
              that.setData({
                get_guidepage_info: res.data.get_guidepage_info,
              });
            }
          } else {
            wx.showModal({
              title: "提示",
              content: res.msg,
              showCancel: false,
              success(res) {
                if (res.confirm) {
                  wx.navigateBack({
                    delta: 2,
                    fail() {
                      wx.reLaunch({
                        url: '/packageG/index/index',
                      });
                    },
                  });
                }
              },
            });
            // 赋值给foot组件
            let footChild = this.selectComponent("#footChild");
            footChild.setData({
              isGoods: false,
            });
            that.setData({
              isGoods: false,
            });
          }
        },
        fail: function (res) {
          console.log(res.msg);
        },
      });
    },

    retailPage() {
      let data = this.data.prop_goods_info;
      this.getData(data);
      this.setData({
        goods_info: data,
        goods_plugin: data.plugin || {},
        gooddatas: data,
      });
    },
    getYZSupplier() {
      let urlStr = app.getNetAddresss("plugin.yz-supply.frontend.goods.option");
      //供应链的商品 根据用户默认地址判断是否有库存可购买，如果没库存不满足购买条件可提示或下单按钮灰色。
      app._postNetWork({
        url: urlStr,
        data: {
          goods_id: this.data.goodsId,
        },
        success: (resdata) => {
          let res = resdata.data;
          if (res.result == 1) {
            let options_address = res.data;
            this.getArrEqual(options_address, this.data.goodsInfo.has_many_options);
          }
        },
      });
    },
    getJHSupplier() {
      let urlStr = app.getNetAddresss("plugin.jd-supply.frontend.goods.option");
      //聚合供应链的商品 根据用户默认地址判断是否有库存可购买，如果没库存不满足购买条件可提示或下单按钮灰色。
      app._postNetWork({
        url: urlStr,
        data: {
          goods_id: this.data.goodsId,
        },
        success: (resdata) => {
          let res = resdata.data;
          if (res.result == 1) {
            let options_address = res.data;
            this.getArrEqual(options_address, this.data.goodsInfo.has_many_options);
          }
        },
      });
    },
    getArrEqual(arr1, arr2) {
      //聚合供应链的商品，plugin.jd-supply.frontend.goods.option接口返回为1的才去取库存，返回为0的就库存直接是0
      for (let i = 0; i < arr2.length; i++) {
        if (arr1[arr2[i].id] == 0) {
          this.data.goodsInfo.has_many_options[i].stock = 0;
        }
      }
      this.data.goodsInfo.stock = this.data.goodsInfo.has_many_options[0].stock; //设置库存
      this.setData({
        goodsInfo: this.data.goodsInfo
      });
    },
    handleMicro(index, maxLength, micro_communities) {
      let img_list = [];
      for(let i=0;i<micro_communities.list.length; i++) {
        if(micro_communities.list[i].has_many_image && micro_communities.list[i].has_many_image[index]) {
          img_list.push(micro_communities.list[i].has_many_image[index]);
        }
      }
      this.setData({
        min_micro: this.data.min_micro.concat(img_list)
      });
      if(index < maxLength && this.data.min_micro.length < 12) {
        index++;
        this.handleMicro(index, maxLength, micro_communities);
      }
    },
    getGoodsPage() {
      let data = this.data.prop_goods_info;
      // data全部数据
      let footChild = this.selectComponent("#footChild");
      let buyNowChild = this.selectComponent("#buyNowChild");

      if (data.plugin) {

        if (data.plugin.micro_communities) {
          // 微社区帖子
          let num_list = [];
          for(let i=0;i<data.plugin.micro_communities.list.length; i++) {
            num_list.push(data.plugin.micro_communities.list[i].has_many_image.length);
          }

          //计算最长的图片数组长度   不断递归整合到this.min_micro
          let maxLength = Math.max(...num_list);
          let index = 0;

          this.handleMicro(index, maxLength - 1, data.plugin.micro_communities);

          // this.min_micro再重新分成6张一组
          let list = [];
          for(let i=0;i<this.data.min_micro.length;) {
            list.push(this.data.min_micro.slice(i, i + 6));
            i += 6;
          }
          if(list.length > 0) {
            this.data.tabList.push({id: 1,name: '关联微贴'});
          }

          this.setData({
            min_micro: list,
            tabList: this.data.tabList
          });
        }
        if (data.plugin.is_room && data.plugin.is_room == 1) {
          this.getLiveList();
        }
        if (data.plugin.wechatcircle_open && data.plugin.wechatcircle_open == 1) {
          this.setData({
            wechatcircle_open: 1,
          });
        }

        if(data.plugin && data.plugin.project_template) {
          this.data.tabList.push({id: 3,name: '知识库'});
          this.setData({
            knowledgeList: data.plugin.project_template.list,//供应链知识库
            tabList: this.data.tabList
          });
        }
        if(data.plugin && data.plugin.customized_group) {
          let startTime = data.plugin?.customized_group?.start_time;
          this.setData({
            grBeginTime:startTime,
            isBuy:false,
            isTime:false,
            beginTime:0,
            grisTime:this.groupTime(startTime)
          })
        }
      }

      this.setData({
        broadcast_data: data.plugin?.broadcast_data?data.plugin?.broadcast_data:[],
        favorite: data.is_favorite ? (data.is_favorite.status == 1 ? true : false) : false,
        freight_pricing: data.plugin?.freight_pricing ? data.plugin?.freight_pricing : {},
        luck_draw: data.plugin?.luck_draw ? data.plugin?.luck_draw : {},
        goods_plugin: data.plugin || {},
        goods_info: data,
        gooddatas: data,
      });
      // foot子组件赋值
      footChild.setData({
        goods_info: data, //酒店需要用到最外层的数据
        goodsInfo: data.get_goods,
        service_QRcode: data.customer_service.service_QRcode,
        service_mobile: data.customer_service.service_mobile,
        cservice: data.customer_service.cservice,
        customer_open: data.customer_service.customer_open == '0' ? false : data.customer_service.customer_open,
      });
      // buynow子组件赋值
      buyNowChild.setData({
        goods_plugin: data.plugin || {},
      });
      this.getData(data.get_goods);
      if (data.plugin && data.plugin.wx_video_link) {
        this.setData({
          wx_video_link: data.plugin.wx_video_link,
        });
      }
      //运费说明
      let Shipping = this.data.freight_pricing.content;
      try {
        if (Shipping && Shipping.indexOf("&#") <= -1) {
          WxParse.wxParse("Shipping", "html", Shipping, this);
        }
      } catch (e) {
        console.log(e);
      }

      if (data.plugin&&data.plugin.get_guidepage_info) {
        this.setData({
          get_guidepage_info: data.plugin.get_guidepage_info,
        });
      }

      // 租赁商品
      if (!app._isTextEmpty(data.plugin&&data.plugin.lease_toy)) {
        this.setData({
          isRent: data.plugin.lease_toy.is_lease == 1 ? true : false,
          isRentBuyShow: data.plugin.lease_toy.immed_goods_id == 0 ? false : true,
        });
        if (!app._isTextEmpty(data.plugin.lease_toy.is_rights)) {
          this.setData({
            isRight: data.plugin.lease_toy.is_rights == 1 ? true : false,
          });
        }
      }
      // 中台租赁商品
      if( !app._isTextEmpty(data.plugin && data.plugin.yz_supply_lease) && data.plugin.yz_supply_lease.is_yz_supply_lease == 1){
        this.setData({
          isRent : true
        })
      }

      // 自购省
      if (data.plugin&&data.plugin.selfbuy_discount) {
        this.setData({
          selfbuy_discount: data.plugin.selfbuy_discount,
        });
      }

      if(data.get_goods.plugin_id == 44) {
        this.getJHSupplier();
      }

      if(data.get_goods.plugin_id == 120) {
        this.getYZSupplier();
      }
    },
    //获取数据
    getData(data) {
      // console.log(data,'get_goods数据')
      // get_goods数据
      if (Number(data.market_price) == 0) {
        data.notMarket_price = 0;
      } else {
        data.notMarket_price = 1;
      }
      this.setData({
        goodsInfo: data,
        xqBoxShow:data.detail_show?true:false
      });
      // 分享的自定义图片
      wx.setStorageSync("GoddsShareImg", data.thumb);
      if (this.data.goodsInfo.member_discount) {
        if (app._isTextEmpty(this.data.goodsInfo.member_discount.discount)) {
          this.setData({
            openVip: 1,
          });
        } else {
          this.setData({
            openVip: this.data.goodsInfo.member_discount.discount,
          });
        }
      }

      this.initPopView(); //初始化弹窗view
      this.setDataByTabIndex(); //设置商品详情
      // this.setIsLove(); 判断是否有爱心值 移到priceTitleRepertorySales组件  // this.setIsAddCart(); 判断是否能加入购物车 移到foot组件
      // 赋值给foot组件
      let footChild = this.selectComponent("#footChild");
      footChild.setData({
        isGoods: true,
      });
      this.setData({
        isGoods: true,
      });
      //限时购
      if (!app._isTextEmpty(data.buy_limit)) {
        this.setData({
          isBuy: data.buy_limit.status == 1 ? true : false,
        });
        footChild.setData({
          isBuy: data.buy_limit.status == 1 ? true : false,
        });
        this.data.beginTime = data.buy_limit.start_time;
        this.data.endTime = data.buy_limit.end_time * 1000;
        //判断倒计时模块是否开启
        this._timeCompare(this.data.beginTime);
      }
    },
    // 运费说明
    changeFold() {
      let _isfold = !this.data.isfold;
      let _heigth = this.data.freightPricing_main_heigth_var;
      let that = this;
      if (!this.data.isfold) {
        if (!_heigth) {
          this.createSelectorQuery()
            .select(".freightPricing_main_heigth")
            .boundingClientRect(function (rect) {
              _heigth = rect.height;
              that.setData({
                freightPricing_main_heigth_var: _heigth * 2,
                freightPricing_main_heigth: _heigth * 2,
                isfold: _isfold,
              });
            })
            .exec();
        } else {
          this.setData({
            freightPricing_main_heigth: _heigth,
            isfold: _isfold,
          });
        }
      } else {
        this.setData({
          freightPricing_main_heigth: 80,
          isfold: _isfold,
        });
      }
    },
    // 视频拓展链接
    getVideoLink() {
      wx.showLoading({
        title: "正在生成中...",
      });
      // 生成视频号链接
      let that = this;
      let urlStr = app.getNetAddresss("plugin.wx-video-link.frontend.index.index");
      urlStr += "&id=" + this.properties.goodsId;
      app._getNetWork({
        showToastIn: false,
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            if (res.data.article_url == "" || res.data.article_url == null || res.data.article_url == undefined) {
              setTimeout(() => {
                that.getVideoLink();
              }, 3000);
            } else {
              that.setData({
                article_url: res.data.article_url,
                showVideoLink: true,
                showSahre: false,
              });
              setTimeout(function () {
                wx.hideLoading();
              }, 800);
            }
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
        fail: function (res) {},
      });
    },
    // 复制链接
    onCopy() {
      wx.setClipboardData({
        data: this.data.article_url,
        success(res) {
          wx.showToast({
            title: "复制成功",
            icon: "none",
            duration: 3000,
          });
        },
        fail() {
          wx.showToast({
            title: "复制失败",
            icon: "none",
            duration: 3000,
          });
        },
      });
      this.setData({
        showVideoLink: false,
        article_url: "",
      });
    },
    // *********************************    拼团   ******************************************
    // 获取数据
    groupGetData() {
      let footChild = this.selectComponent("#footChild");
      let buyNowChild = this.selectComponent("#buyNowChild");
      let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.controllers.fight-groups-goods.get-goods");
      let storeId = this.properties.store_id;
      if (storeId && storeId != 0 && storeId != "undefined") {
        this.setData({
          is_o2o: true,
        });
        footChild.setData({
          is_o2o: true,
        });
        urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.frontend-fight-groups-goods.get-goods");
        urlStr += "&store_id=" + storeId;
      }
      
      if(this.data.goodsType === "ywmGroup") {
        urlStr = app.getNetAddresss("plugin.ywm-fight-groups.frontend.controllers.fight-groups-goods.get-goods");
        if(this.data.cid&&Number(this.data.cid) > 0) urlStr += "&member_open_group_card_id=" + this.data.cid;
      }

      if (this.data.fight_groups != "undefined") {
        urlStr += "&fight_groups_goods_id=" + this.data.fight_groups;
      }
      
      urlStr += "&id=" + this.data.activityid;
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            res.data.lottery_desc = res.data.lottery_desc?res.data.lottery_desc.split("\n"):'';
            if (res.data.goods_info.favorable_rate) {
              this.setData({
                thirKong: true,
                third_content: res.data.goods_info.get_comment.data,
              });
            } else {
              this.setData({
                thirKong: false,
                noMoreComment: true,
                third_content: [],
              });
            }
            this.setData({
              gooddatas: res.data,
              goodsInfo: res.data.goods_info,
              goods_info: res.data.goods_info,
              group_price: res.data.min_price,
              popStock: res.data.goods_info.stock,
              goodsId: res.data.goods_id,
              // 时间
              end_time: res.data.end_time,
              start_time: res.data.start_time,
              // 0没有珍珠，1有珍珠
              is_pearl: res.data.is_pearl,
              // 消费积分插件是否开启0没有珍珠，1有珍珠
              is_integral: res.data.is_integral,
              // 参与人数
              member_count: res.data.member_count,
              // 活动当前轮次
              present_bout: res.data.present_bout,
              // 当前会员拼中次数
              my_win_count: res.data.my_win_count,
              activityId: res.data.id,
            });
            footChild.setData({
              group_price: res.data.min_price,
              gooddatas: res.data,
            });
            buyNowChild.setData({
              gooddatas: res.data,
            });
            // 分享的自定义图片
            wx.setStorageSync("GoddsShareImg", res.data.goods_info.thumb);
            if (app._isTextEmpty(this.data.group_price)) {
              this.setData({
                group_price: "",
              });
            }

            if (!app._isTextEmpty(res.data.display_team.end_time)) {
              this.setData({
                end_time_team: res.data.display_team.end_time, // 队伍时间
              });
            }
            if (!app._isTextEmpty(this.data.end_time)) {
              this.setData({
                isendTime: true,
              });
            } else {
              this.setData({
                isendTime: false,
              });
            }

            this.setData({
              first_content: res.data.goods_info.content,
            });
            let data = this.data.gooddatas.has_many_level;
            data.map((item, index) => {
              if (index == 0) {
                item.bool = true;
              } else {
                item.bool = false;
              }
            });
            this.setData({
              has_many_level: data,
            });
            this.initPopView();
            this.triggerEvent("parentEvent", [res.data.share_title || res.data.title]);
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
      });
    },

    // 显示去参团列表弹层
    showGroupMoreChild() {
      if (this.data.gooddatas.join_status === false && (this.data.goodsType === "group_goods" || this.data.goodsType === "ywmGroup")) {
        wx.showToast({
          title: '今日该活动已达到参与次数',
          icon: "none",
          duration: 3000
        });
        return;
      }
      let selfChild = this.selectComponent("#Tag");
      selfChild.showGroupMore();
    },

    // 控制海报显示
    selfShowPop(e) {
      let status = e.detail;
      let footChild = this.selectComponent("#footChild");
      footChild.setData({
        show1: status,
        service_QRcode: this.data.gooddatas.store.service_QRcode,
        service_mobile: this.data.gooddatas.store.service_mobile,
        customer_open:1,
        cservice: this.data.gooddatas.store.cservice,
      });
    },
    // *********************************    拼团 end   ******************************************

    // *********************************    抢团 start   ******************************************
    grabGroupData() {
      let that = this;
      let urlStr = null;
      let tagChild = this.selectComponent("#Tag");
      urlStr = app.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData");
      urlStr += "&goods_id=" + this.data.goodsId + "&art=goodsDetail";
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            let thumb = [];
            let team = res.data.goodsDetail.team;
            tagChild.setData({
              teamLis: team,
            });
            let length = Math.ceil(team.length / 2);
            let splitTeam = [];
            if (team.length > 0) {
              for (let index = 0; index < length; index++) {
                splitTeam.push(team.splice(0, 2));
              }
            }
            thumb.push(res.data.goodsDetail.goods.thumb);
            that.setData({
              gooddatas: res.data.goodsDetail.goods,
              popStock: res.data.goodsDetail.goods.stock,
              team: splitTeam,
              third_content: res.data.goodsDetail.comment.data,
              "gooddatas.thumb": thumb,
              "gooddatas.price": res.data.goodsDetail.goods.price_num,
              first_content: res.data.goodsDetail.goods.content,
              end_time: res.data.goodsDetail.goods.end_time * 1000,
              start_time: res.data.goodsDetail.goods.start_time,
              leader_partake: res.data.goodsDetail.leader_partake,
              leader_not_join_invalid: res.data.goodsDetail.leader_not_join_invalid||0,
              activityId: res.data.goodsDetail.goods.activity_id,
            });
            that.initPopView(); //初始化弹窗view
            that._timeCompare(res.data.goodsDetail.goods.start_time);
            // 改成组件需要的数据字段 foot buyNow
            that.setData({
              goodsInfo: that.data.gooddatas,
            });
            // 传给buyNow子组件的
            let buyNowChild = this.selectComponent("#buyNowChild");
            buyNowChild.setData({
              popStock: res.data.goodsDetail.goods.stock,
              popThumb: this.data.popThumb,
              popPrice: this.data.popPrice,
              goodsDescription: this.data.goodsDescription,
              optionsMaxCount: this.data.optionsMaxCount,
              activityId: this.data.activityId,
              skuImages: this.data._optionArr,
            });
            // 分享的自定义图片
            wx.setStorageSync("GoddsShareImg", thumb[0]);
            that.triggerEvent("parentEvent", [that.data.gooddatas.title]);
            let start_time = new Date().getTime() / 1000;
            that.setData({
              nowTime: start_time,
            });
            let _team = that.data.team;
            for (let i = _team.length - 1; i >= 0; i--) {
              if (_team[i].end_time <= start_time) {
                _team.splice(i, 1); //删除下标为i的元素
              }
            }
            that.setData({
              team: _team,
            });

          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
      });
    },

    // *********************************    抢团 end   ******************************************
    // ***********************************  拼团二开 珍惠拼 /********************************** */
    zhpGroupData() {
      let urlStr = null;
      let that = this;
      let footChild = this.selectComponent("#footChild");
      let buyNowChild = this.selectComponent("#buyNowChild");
      urlStr = app.getNetAddresss("plugin.zhp-group-lottery.frontend.goods.get-goods");
      urlStr += "&id=" + this.data.goodsId;
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            that.setData({
              gooddatas: res.data,
              goodsInfo: res.data.get_goods,
              goods_info: res.data.get_goods,
              group_price: res.data.min_price,
              popStock: res.data.get_goods.stock,
              goodsId: res.data.goods_id,
              // 时间
              end_time: res.data.end_time,
              start_time: res.data.start_time,
              first_content: res.data.get_goods.content
            });
            that.initPopView(); //初始化弹窗view
            footChild.setData({
              group_price: res.data.min_price,
              gooddatas: res.data,
            });
            buyNowChild.setData({
              gooddatas: res.data,
            });
            this.triggerEvent("parentEvent", ['', '']);
            wx.setNavigationBarTitle({
              title: '拼团活动详情',
            });
            // let article = this.data.first_content;
            // try {
            //   if (article.indexOf("&#") <= -1) {
            //     WxParse.wxParse("article", "html", article, this);
            //   }
            // } catch (e) {
            //   //TODO handle the exception
            // }
            // 分享的自定义图片
            wx.setStorageSync("GoddsShareImg", res.data.get_goods.thumb);
            wx.hideLoading({
              success: (res) => {},
            });
            this.triggerEvent("parentEvent", [res.data.title, res.data.share_content]);
            that._timeCompare(res.data.start_time);
            this.zhpBroadcast();
          } else {
            wx.hideLoading({
              success: (res) => {},
            });
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
      });
    },
    // 飘窗
    zhpBroadcast() {
      let that = this;
      let urlStr = app.getNetAddresss("plugin.zhp-group-lottery.frontend.goods.get-window-list");
      wx.showLoading({
        title: '加载中',
      });
      app._getNetWork({
        url: urlStr,
        data: {
          activity_id: this.data.activityId
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            res.data.goodsId = this.data.goodsId;
            res.data.integral_name = that.data.gooddatas.love_plugin_name;
            that.setData({
              broadcast_data: res.data
            });
            wx.hideLoading({
              success: (res) => {},
            });
          } else {
            wx.hideLoading({
              success: (res) => {},
            });
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
      });
    },
    // ***********************************  0.1元拼二开 group-work /********************************** */
    groupWorkData() {
      let urlStr = null;
      urlStr = app.getNetAddresss("plugin.group-work.frontend.modules.goods.controllers.detail.index");
      urlStr += "&record_id=" + this.properties.activityid;
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            this.setData({
              gooddatas: res.data,
              goodsInfo: res.data.goods_info,
              goods_info: res.data.goods_info,
              popStock: res.data.stock,
              goodsId: res.data.goods_id,
              group_price: res.data.min_price,
              // 时间
              isendTime: true,
              end_time: res.data.end_time,
              start_time: res.data.start_time,
              first_content: res.data.goods_info.content,
              customer_open: res.data.customer_service.customer_open == "1" ? true : false,
              service_QRcode: res.data.customer_service.service_QRcode,
              service_mobile: res.data.customer_service.service_mobile,
            });
            let footChild = this.selectComponent("#footChild");
            // foot子组件赋值
            footChild.setData({
              service_QRcode: res.data.customer_service.service_QRcode,
              service_mobile: res.data.customer_service.service_mobile,
              cservice: res.data.customer_service.cservice,
              customer_open: res.data.customer_service.customer_open,
            });
            this.initPopView(); //初始化弹窗view
            wx.setNavigationBarTitle({
              title: '拼团活动详情',
            });
            // 分享的自定义图片
            wx.setStorageSync("GoddsShareImg", res.data.goods_info.thumb);
            wx.hideLoading({
              success: (res) => {},
            });
            this.triggerEvent("parentEvent", [res.data.share_title, res.data.share_content]);
            this._timeCompare(res.data.start_time);
          } else {
            wx.hideLoading({
              success: (res) => {},
            });
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 3000,
            });
          }
        },
      });
    },
    pushCart(e){
      let item = e.currentTarget.dataset.item;
      let urlStr = app.getNetAddresss("member.member-cart.store");
      wx.showLoading({
        title: '加载中',
      });
      app._getNetWork({
        url: urlStr,
        data: {
          goods_id: item.goods_id,
          total:'1',
          option_id:item.goods_option_id
        },
        success: (resdata) => {
          var res = resdata.data;
          wx.hideLoading();
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
          this.setData({
            cart_num: res.data.cart_num
          });
          
        },
      });
    },

   /***********律师二开***************/
    lawyerChange(data){
      this.setData({
        "lawyerInfo.name":data.detail.name,
        "lawyerInfo.price":data.detail.service_data.amount,
        "lawyerInfo.status":data.detail.status,
        "lawyerInfo.service_day":data.detail.service_data.day,
        "lawyerInfo.service_type":data.detail.service_data.type,
        "lawyerInfo.l_id":data.detail.id,
        "lawyerInfo.l_name":data.detail.status,
        "lawyerInfo.lf_id":data.detail.lf_id,
        "lawyerInfo.lf_name":data.detail.lawyer_firm.name,
        "lawyerInfo.lf_province_name":data.detail.lawyer_firm.province_name,
        "lawyerInfo.lf_city_name":data.detail.lawyer_firm.city_name,
        "lawyerInfo.lf_area_name":data.detail.lawyer_firm.area_name,
        "lawyerInfo.lf_street_name":data.detail.lawyer_firm.street_name,
        "lawyerInfo.lf_address_detail":data.detail.lawyer_firm.address_detail,
      })
    },
    _playLawyer(){
        if(!this.data.lawyerInfo.name){
          return  this.$toast("请选择律师")
        }
        console.log(this.data.lawyerInfo)
        if(this.data.lawyerInfo.service_type == "tel" && this.data.lawyerInfo.status==0){
           return  this.$toast("该律师已休息，暂不能购买电话咨询服务")
        }
        let {l_id,price,service_type,l_name,lf_id,lf_name,service_day,lf_province_name,lf_city_name,lf_area_name,lf_street_name,lf_address_detail} = this.data.lawyerInfo
        let json = {
          goods_id:this.data.goodsId,
          l_id,
          price,
          service_type:service_type=="tel"?1:2,
          l_name,
          lf_id ,
          lf_name,
          lf_province_name,
          lf_city_name,
          lf_area_name,
          lf_street_name,
          lf_address_detail
        }
        if(service_day){
          json.service_day = service_day
        }
        app._postNetWork({
          url:app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.create"),
          data:json,
          success:res => {
            console.log(res)
            if(res.data.result == 1){
              let order_ids = res.data.data.order_ids
              wx.navigateTo({
                url: '/packageD/buy/orderPay/orderPay?order_id='+order_ids,
              })
            }else{
              this.$toast(res.data.msg)
            }
          }
        })
    },

    copyMidLink(){
      let mid = wx.getStorageSync("yz_uid");
      let url = `${app.data.host}/addons/yun_shop/api.php?i=${app.data.uniacid}&route=plugin.min-app.Frontend.Controllers.page.goods-url&goods_id=${this.data.goodsInfo.id}&mid=${mid}`;
      this.onClipboardData(url);
    },
    getShortLink(e){
      let mid = wx.getStorageSync("yz_uid");
      let plu = e.currentTarget.dataset.plu;
      let json = {};
      let api = 'plugin.wechat-short-link.frontend.index.get-url'
      if(plu == 'shortlink') {
        json = {
          goods_id: this.data.goodsInfo.id,
          applet_url: `packageA/detail_v2/detail_v2?id=${this.data.goodsInfo.id}`
        }
      } else if (plu == 'privatechain') {
        api = 'plugin.private-chain.frontend.index.index';
        json = {
          path: `packageA/detail_v2/detail_v2`,
          params: `id=${this.data.goodsInfo.id}&mid=${mid}`,
          share_type: 'goods_detail',
          id: this.data.goodsInfo.id
        }
      }
      app._postNetWork({
        url: app.getNetAddresss(api),
        data: json,
        success:res => {
          console.log(res)
          if(res.data.result == 1){
            this.setData({
              videoLinkUrl: res.data.data.url||false,
              videoLinkText: res.data.data.text,
              videoLinkDesc: res.data.data.desc,
              showShortLink: true,
              showSahre: false
            });
          }else{
            app.tips(res.data.msg)
          }
        }
      })
    },
    onClipboardData(data){
      wx.setClipboardData({
        data: data,
        success(res) {
          wx.showToast({
            icon: 'none',
            title: '复制成功',
            duration: 1000
          });
        },fail(err){
          console.log(err);
        }
      });
    },
    onCopyShortLink(e){
      let type = e.currentTarget.dataset.type;
      this.onClipboardData(this.data[type]);
    },
    clonePop(e){
      let { tag, status } = e.target.dataset;
      this.setData({
        [tag]: status
      })
    },
    setGoodAddress(e){
      this.setData({
        delivery_address: e.detail
      });
    },
    setShowGoodAddress(){
      let delivery_address = this.selectComponent("#delivery_address");
      delivery_address.setData({
        showAddressList: true
      })
    }
  },
});
